<template>
<div>
    <x-header class="myHeader" :left-options="{backText: ''}">
        <span style="color: #000">密码重置</span>
    </x-header>
 
    <div class="page-content">
        <div class="progress">
            <img class="process-img">
        </div>
        <div class="myGroup">
            <div class="myGroup-item" >
                <div class="row">
                    <input ref="pswd0" placeholder="请输入新密码" maxlength="20" type="password" v-model="password" />
                    <!-- <i v-if="isEye" id="eye-fill" @click="eyeOff"></i>
                    <i v-else id="eye-no" @click="eyeOn"></i> -->
                    <i class="icon iconfont icon-biyanjing" v-if="isEye" @click="eyeOff"></i>
                    <i class="icon iconfont icon-chakan2" v-else  @click="eyeOn"></i>

                    <span v-if="isWeek" class="strong-level" id="week-char">弱</span>
                    <span v-if="isMid" class="strong-level" id="mid-char">中</span>
                    <span v-if="isStrong" class="strong-level" id="strong-char">强</span>
                </div>
            </div>
            <div v-if="isWeek" class="week-color"></div>
            <div v-if="isMid" class="mid">
                <div class="mid-color"></div>
                <div class="mid-color"></div>
            </div>
            <div v-if="isStrong" class="strong">
                <div class="strong-color"></div>
                <div class="strong-color"></div>
                <div class="strong-color" style="margin-right: 2rem;"></div>
            </div>
            <van-notice-bar   left-icon="info-o">
                6-20位密码，包含英文大小写、数字和特殊字符
            </van-notice-bar>

            <div class="myGroup-item">
            <input ref="pswd1" placeholder="再次输入新密码" maxlength="20" type="password" v-model="passwordAgain" />
            </div>
            <button class="myBtn" @click="btnClick">下一步</button>
        </div>
    </div>
 
</div>
</template>

<script>
import { XHeader } from "vux";
export default {
    name: "forgetSecret2",
    components: {
        XHeader,
    },
    data() {
        return {
            account: null,
            id: null,
            password: null,
            passwordAgain: null,
            isWeek: false,
            isMid: false,
            isStrong: false,
            isEye: false,
        };
    },
    mounted() {
        this.account = this.$route.query.account;
        this.id = this.$route.query.id;
    },
    methods: {
        eyeOff() {
            this.isEye = false;
            this.$refs.pswd0.type = "password";
            this.$refs.pswd1.type = "password";
        },
        eyeOn() {
            this.isEye = true;
            this.$refs.pswd0.type = "text";
            this.$refs.pswd1.type = "text";
        },
        btnClick() {
            
            if (this.password != this.passwordAgain) {
                return this.$vux.toast.show({
                    type: "warn",
                    width: "60vw",
                    text: '<p style="font-size:0.5rem">前后密码不一致</p>'
                });
            }
            if (this.password.length == 0) {
                return this.$vux.toast.show({
                    type: "warn",
                    width: "60vw",
                    text: '<p style="font-size:0.5rem">密码不为空</p>'
                });
            }
            this.$router.push({
                path: "/forgetSecret",
                query: { password: this.password }
            });
            // let defer = this.baseService.postForm(this.__ctx + "/org/login/updatePassword", {
            //     account: this.account,
            //     IDCard: this.id,
            //     newPassword: this.password
            // });
            // defer.then(data => {
            //     if (data.isOk) {
            //         let _this = this;
            //         // this.$vux.toast.show({
            //         //     text: data.msg || "修改密码成功",
            //         // });
            //         this.$vux.toast.show({
            //             width: "60vw",
            //             text: '<p style="font-size:0.5rem">'+data.msg || "修改密码成功"+'</p>'
            //         });
            //     } else {
            //         // this.$vux.toast.show({
            //         //     type: "warn",
            //         //     text: data.msg
            //         // });
            //         this.$vux.toast.show({
            //             type: "warn",
            //             width: "60vw",
            //             text: '<p style="font-size:0.5rem">'+data.msg+'</p>'
            //         });
            //     }
            // });
        }
    },
    watch: {
        password(n, o) {
            let reg0 = /^(\d{6,20})|([a-z]{6,20})|([A-Z]{6,20})$/;
            let reg1 = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
            let reg2 = /(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,20}/;
            if (reg0.test(n)) {
                this.isWeek = true;
                this.isMid = false;
                this.isStrong = false;
            }
            if (reg1.test(n)) {
                this.isWeek = false;
                this.isMid = true;
                this.isStrong = false;
            }
            if (reg2.test(n)) {
                this.isWeek = false;
                this.isMid = false;
                this.isStrong = true;
            }
            if (n.length == 0) {
                this.isWeek = false;
                this.isMid = false;
                this.isStrong = false;
            }
        }
    }
}
</script>

<style scoped lang="less">

.myGroup {
    width: 95%;
    margin:0 auto;
    margin-top:70px;
    // margin: 1.2rem auto;
    .week-color {
        background-color: rgba(220, 48, 25, 1);
        width: calc(~"30% ");
        height: 0.1rem;
        // margin-left: 1.48rem;
    }
    .mid {
        display: flex;
        flex-direction: row;
        // margin-left: 1rem;
        .mid-color {
            background-color: rgba(255, 217, 43, 1);
            width: calc(~"30% ");
            height: 0.1rem;
            // margin-left: 0.5rem;
        }
    }
    .strong {
        display: flex;
        flex-direction: row;
        // margin-left: 1rem;
        .strong-color {
            background-color: rgba(14, 223, 81, 1);
            width: calc(~"30% ");
            height: 0.1rem;
            // margin-left: 0.5rem;
        }
    }
    .tip {
        margin-top: 0rem;
        background-color: rgba(255, 240, 191, 1);
        width: calc(~"90% ");
        margin-left: 15px;
        #warning {
            content: url(../../assets/xc-zhuyi.png);
            width: 1.2rem;
            vertical-align: middle;
        }
        span {
            vertical-align: middle;
        }
    }
    .myGroup-item {
    // border: 1px solid #dcdee2;
    // border-radius: 20px;
        height: 42px;
        position: relative;
        line-height: 42px;
        margin-top:0.3rem;
        background-color: #fff;
        border-radius: 6px;
        .row{
            display: flex;
            .icon{
                padding:0 10px;
            }
            .strong-level{
                padding:0 10px 0 0;
            }
        }
        // #eye-fill {
        //     position: relative;
        //     width: 1.2rem;
        //     top: 0.2rem;
        //     right: 4rem;
        //     content: url(../../assets/eye-fill.png);
        // }
        // #eye-no {
        //     position: relative;
        //     width: 1.2rem;
        //     top: 0.2rem;
        //     right: 4rem;
        //     content: url(../../assets/no_eye.png);
        // }
        #week-char {
            color: rgba(220, 48, 25, 1);
        }
        #mid-char {
            color: rgba(255, 217, 43, 1);
        }
        #strong-char {

            color: rgba(14, 223, 81, 1);
        }
        input {
            border: 0;
            outline: 0;
            border: 1px solid #fff;
            background-color: #fff;
            border-radius: 6px;
            -webkit-appearance: none;
            font-size: inherit;
            color: inherit;
            height: calc(~"100%");
            vertical-align: top;
            // margin-left: 15px;
            color: black;
            // font-size: 1.2em;
            width: calc(~"90% ");
            height: 42px;
        }
    }
}


.myBtn {
  margin-top: 3rem;
  width: 80%;
  touch-action: none;
  border-radius: 20px;
  background-color: rgba(220, 48, 25, 1);
  position: relative;
  display: block;
  margin-left: auto;
  margin-right: auto;
  padding-left: 14px;
  padding-right: 14px;
  box-sizing: border-box;
  font-size: 18px;
  text-align: center;
  text-decoration: none;
  color: #ffffff;
  line-height: 2.33333333;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  overflow: hidden;
  border: none;
}
.van-notice-bar{
    margin-top: 5px;
    // margin-bottom:0.1rem;
}
/deep/ .van-notice-bar__content{
    font-size: 0.4rem;
}
.progress{
    position: fixed;
    left:0;
    top:44px;
    z-index: 100;
}
</style>